<?php

/**
 * Renderers client side JavaScript section handling various actions according to the given query parameters.
 * if action == 'showonmap' => shows on the map the given friend's (by query param 'fid') popup baloon  
 */
include_once './User.php';
include_once './log4php/Logger.php';

Logger::configure('./log4j.properties');

/**
 * 
 * @param Situare $situare
 * @return unknown_type
 */
function handleAction($situare) {
    $log = Logger::getLogger(__METHOD__);
    $returnStr = '';

    $user = $situare->getUser();

    if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'showonmap') {
        $fid = isset($_REQUEST['fid']) ? $_REQUEST['fid'] : null;
        $log->debug('action==showonmap: Will be processed with args fid=' . $fid . ', user=' . (isset($user) ? $user->fb_uid : 'null'));
        if ($fid == null) {
            $log->error('action==showonmap: Missing \'fid\' request parameter!');
            return $returnStr;
        }
        if ($user == null) {
            $log->error('action==showonmap: Logged in user is null!');
            return $returnStr;
        }

        $ulon = (isset($user->fb_location) ? $user->fb_location->lon : 0);
        $ulat = (isset($user->fb_location) ? $user->fb_location->lat : 0);

        if ($user) {
            $returnStr .= "\n" . '<script type="text/javascript">';
            $returnStr .= "\n" . 'activateTab(\'mapView\');';
            $returnStr .= "\n" . 'dynamicOSMLoad(function(){layerFriends.showMeAndMyFriend(' . $ulon . ', ' . $ulat . ', ' . $fid . ');});';
            $returnStr .= "\n" . '</script>';
        }
    }

    return $returnStr;
}

?>